<template>
  <div id="app">
    <h2>测试题</h2>
    <div v-for="(subject, index) in subjects" :key="index">
      <subject-item :id="index" @answer-submitted="handleAnswerSubmitted"></subject-item>
    </div>
    <div>
      <flag-item v-for="(result, index) in results" :key="index" :status="result.status"></flag-item>
    </div>
  </div>
</template>

<script>
import SubjectItem from './components/SubjectItem.vue';
import FlagItem from './components/FlagItem.vue';

export default {
  components: {
    SubjectItem,
    FlagItem
  },
  data() {
    return {
      subjects: Array.from({ length: 5 }, (_, i) => ({ id: i })),
      results: Array.from({ length: 5 }, () => ({ id: 0, status: 'undo' }))
    };
  },
  methods: {
    handleAnswerSubmitted({ id, isCorrect }) {
      this.results[id] = { id, status: isCorrect ? 'right' : 'error' };
    }
  }
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>